package algorithm.poj.p3000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;


/**
 * 分析：
 * 实现：
 * 经验：
 * 教训：
 * 
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P3438 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P3438.class.getResource("P3438.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		StringBuffer sb = new StringBuffer("");
		String line = stdin.readLine();
		int N = Integer.valueOf(line);
		for (int i = 0; i < N; i ++) {
			line = stdin.readLine().trim();
			char[] array = line.toCharArray();
			//start
			int index = 0;
			char c = array[0];
			int count = 1;
			int[] ns = new int[array.length];
			char[] cs = new char[array.length];
			for (int j = 1; j < array.length; j ++) {
				if (array[j] == c) {
					count ++;
				} else {
					ns[index] = count;
					cs[index] = c;
					c = array[j];
					count = 1;
					index ++;
				}
			}
			ns[index] = count;
			cs[index] = c;
			
			for (int j = 0; j <= index; j ++) {
				sb.append(ns[j]);
				sb.append(cs[j]);
			}
			sb.append("\n");
		}
		System.out.println(sb);
	}
	
}